package com.css.modules.lawRepo.controller;

import com.css.common.utils.PageUtils;
import com.css.common.utils.R;
import com.css.common.validator.ValidatorUtils;
import com.css.common.validator.group.AddGroup;
import com.css.modules.lawRepo.entity.LawRepoDownloadEntity;
import com.css.modules.lawRepo.service.LawRepoDownloadService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/lawRepo/download")
@Api(value = "/download", description = "法律法规下载记录表", tags = "法律法规下载记录表")
public class LawRepoDownloadController {
    @Autowired
    private LawRepoDownloadService downloadService;

    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", dataType = "int", paramType = "query", required = true),
            @ApiImplicitParam(name = "limit", value = "每页条数", dataType = "int", paramType = "query", required = true),
    })
    @RequestMapping(value = "/list" ,method = RequestMethod.GET)
    @ApiOperation(value = "法律法规下载记录表", notes = "返回法律法规下载记录表",
            produces = "application/json")
    public R list(@ApiParam(name="params" ,hidden = true)@RequestParam Map<String, Object> params){
        PageUtils page = downloadService.queryPage(params);
        return R.ok().put("page", page);
    }

    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    @ApiOperation(value = "添加下载记录", produces = "application/json")
    public R insert(@RequestBody LawRepoDownloadEntity entity){
        ValidatorUtils.validateEntity(entity, AddGroup.class);
        LawRepoDownloadEntity message = downloadService.insert(entity);
        return R.ok().put("message",message);
    }

}
